"""
    登录验证
    @author tina
    @since 2023-10-09 00:34:40
"""
from aiapp import utils

r = utils.redis_util.redis_client
from aiapp.utils import mail_util, random_util
from aiapp.setting import application


def auth_verification_code(code, mail):
    """
        验证码验证
        如果是验证成功需要删除掉
    :param code:验证码
    :param mail: 邮箱
    :return:  bool
    """
    mail_code = r.get(application.MAIL_VERIFICATION_CODE_KEY + mail)
    if mail_code is None:
        return False
    flag = code in mail_code
    if flag:
        r.delele(application.MAIL_VERIFICATION_CODE_KEY + mail)
    return flag


def send_verification_code(to):
    """
        发送验证码
    :return:
    """

    return mail_util.send_verification_code(to, "Kngu验证码", "欢迎使用Kngu 验证码是：", random_util.get_code())


if __name__ == '__main__':
    print("main")
